package com.dev.security.controller;

import com.dev.security.service.RoleService;
import com.dev.security.service.UserService;
import com.dev.security.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 角色控制器
 *
 * @author yuboon
 * @version v1.0
 * @date 2020/04/04
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/save")
    public ResponseEntity save(RoleVo roleVo){
        return ResponseEntity.ok(roleService.save(roleVo));
    }

    @PostMapping("/update")
    public ResponseEntity update(RoleVo roleVo){
        return ResponseEntity.ok(roleService.update(roleVo));
    }

    @PostMapping("/remove")
    public ResponseEntity remove(int id){
        return ResponseEntity.ok(roleService.remove(id));
    }

    @PostMapping("/batchRemove")
    public ResponseEntity batchRemove(String ids){
        return ResponseEntity.ok(roleService.batchRemove(ids));
    }

    @GetMapping("/list")
    public ResponseEntity list(RoleVo roleVo, PageVo pageVo){
        ResponseData<List<RoleVo>> result = new ResponseData();
        PageVo<RoleVo> pageVo1 = roleService.selectList(roleVo,pageVo);
        result.setCount(pageVo1.getTotal());
        result.setData(pageVo1.getList());
        return ResponseEntity.ok(result);
    }

    @PostMapping("/assignMenu")
    public ResponseEntity assignMenu(int roleId,String menuIds){

        return ResponseEntity.ok(roleService.assignMenu(roleId,menuIds));
    }

    @GetMapping("/selectMenuByRoleId")
    public ResponseEntity selectMenuByRoleId(int roleId){

        return ResponseEntity.ok(roleService.selectMenuByRoleId(roleId));
    }

}
